import axios from "axios"

const moduleName = {
    namespaced: true,
    state:{
      data:[],
      children_Data:[]
    },
    mutations: {
      set_data:(state,payload)=>{
        state.data = payload
        state.children_Data = payload[0].children
      },
      set_children_Data:(state,payload)=>{
        state.children_Data = state.data[payload].children
      },
      add_children_Data:(state,payload)=>{
        state.children_Data = [...state.children_Data, ...payload]
      }
    },
    actions: {
        get_list: async ({commit})=>{
            let {data} = await axios.get("/api/list")
            commit("set_data",data)
        },
        add_list: async ({commit})=>{
          let {data} = await axios.get("/api/addlist")
          commit("add_children_Data",data)
        }
    },
}
export default moduleName